package cn.edu.scau.cmi.wujiaxian.comprehensive.service;

import java.util.ArrayList;

import cn.edu.scau.cmi.wujiaxian.comprehensive.dao.ScoreDao;
import cn.edu.scau.cmi.wujiaxian.comprehensive.db.Dao;
import cn.edu.scau.cmi.wujiaxian.comprehensive.model.Score;

public class ScoreService {

	public static void main(String[] args) {
		ScoreService scoreService = new ScoreService();
//		scoreService.addScore(30, 45, 20, 100, 100, "201734020122", "SX001");
		scoreService.deleteScore("201734020122", "SX001");
	}
	
	/**
	 * 增加一个学生的成绩数据
	 * @param attendanceScore
	 * @param testScore
	 * @param workScore
	 * @param finalScore
	 * @param totalScore
	 * @param studentNumber
	 * @param courseNumber
	 */
	public void addScore(
			Integer attendanceScore, Integer testScore,
			Integer workScore, Integer finalScore,
			Integer totalScore, String studentNumber,
			String courseNumber) {
		Score score = new Score();
		score.setAttendanceScore(attendanceScore);
		score.setTestScore(testScore);
		score.setWorkScore(workScore);
		score.setFinalScore(finalScore);
		score.setTotalScore(totalScore);
		score.setStudentNumber(studentNumber);
		score.setCourseNumber(courseNumber);
		ScoreDao scoreDao = new ScoreDao();
		scoreDao.add(score);
	}
	
	/**
	 * 删除一个学生的成绩
	 * @param studentNumber
	 * @param courseNumber
	 */
	public void deleteScore(String studentNumber, String courseNumber) {
		Dao scoreDao = new ScoreDao();
		ArrayList<Score> scores = scoreDao.select("studentNumber", studentNumber);
		for (Score score : scores) {
			if (score.getCourseNumber().equals(courseNumber)) {
				scoreDao.delete("id", score.getId());
				break;
			}
		}
	}
	
	
}
